Skip to content

feat: add mongodb-ts-autocomplete package MONGOSH-2034 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
May 22, 2025

Conversation

lerouxb
Copy link
Collaborator

@lerouxb lerouxb commented Mar 19, 2025

Currently still works with fake mql types, but the shell-api ones are at least the real ones.

TODO: separate tickets

@lerouxb lerouxb force-pushed the add-autocomplete-package branch from 24c2ad2 to 8b624a4 Compare March 19, 2025 12:32
@lerouxb lerouxb marked this pull request as draft March 19, 2025 12:33
@lerouxb lerouxb added the wip label Mar 19, 2025
@lerouxb lerouxb force-pushed the add-autocomplete-package branch from 185e497 to 6d9a9d7 Compare March 20, 2025 15:47
import path from 'path';

function replaceImports(code: string) {
// This just makes it possible to work on mql.ts because then the
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually my stubbed mql.ts file doesn't even use the bson library at the moment, but this will become relevant again once we have the real mql.ts or otherwise use something that depends on loading in the bson library.

@lerouxb lerouxb mentioned this pull request May 2, 2025
3 tasks
// TODO: We need MONGOSH-2170 so that we can use the generated MQL types via
// the Shell API to autocomplete fields in
// ServerSchema[databaseName][collectionName].schema
it.skip('completes a collection field name in a query', async function () {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ Just FYI.

'fixtures',
'autocomplete-types.ts',
);
await fs.writeFile(filepath, code, 'utf-8');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. So the problem with doing it this way is that the shell api is now included in the bundle twice. Once in the api export which contains a giant api string and then again on this side where we generate a file to be included.

But I do kinda want to post-process the api here to change imports so unless we do the replaceImports() thing inside shell-api already there's probably no easy way around it.

Until we do the same thing for mql as we do for shell-api we kinda have to read the file as a string on this side and include the result in the bundle anyway so that we can pass that to the language service.

And for bson where we need the library as a string we have to read it at compile time and generate a string to be included in the bundle that can be passed to the language service regardless, because we're probably not going to be modifying the bson library to add that export.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK what I do now is I don't include the shell api inside autocomplete-types.ts. Once we have a real mql.ts we'll do the same for it. MongoDBAutocompleter just adds in the shell api next to autocompleteTypes itself. That way we don't have this in the bundle twice.

So autocomplete-types.ts is only for modules that don't export a a giant string.

@lerouxb lerouxb merged commit a787304 into main May 22, 2025
30 checks passed
@lerouxb lerouxb deleted the add-autocomplete-package branch May 22, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants